Skip to content

Context sensitive array bounds for all function calls#265

Merged
Machiry merged 4 commits into
BigRefactorfrom
iss252
Sep 21, 2020
Merged

Context sensitive array bounds for all function calls#265
Machiry merged 4 commits into
BigRefactorfrom
iss252

Conversation

@Machiry

@Machiry Machiry commented Sep 15, 2020

Copy link
Copy Markdown
Collaborator

We will create context-sensitive bounds key for inferring array bounds. Previously, we did this only for functions that have bounds declarations, but this pull-request extends this to all functions.

Consider the following code:

struct hash_node
{
  int *w_key;
  int *y_key;
  unsigned xo;
  unsigned lo;
};
void ctxsensfunc(int *p, unsigned n) {
    unsigned i;
    for (i=0; i<n; i++) {
	p[i] = 0;
    }
}

int foo() {
    unsigned j;
    struct hash_node *n
    ctxsensfunc(n->w_key, n->xo);
    j = n->lo;
    ctxsensfunc(n->y_key, j);
    return 0;
}

Here, for each of the call-sites of ctxsensfunc we create new BoundsKey and array length inference will correctly infer the length of the structure members as follows:

struct hash_node
{
  _Array_len<int> w_key : count(xo);
  _Array_len<int> y_key : count(lo);
  unsigned xo;
  unsigned lo;
};
void ctxsensfunc(_Array_len<int> p : count(n), unsigned n) {
    unsigned i;
    for (i=0; i<n; i++) {
	p[i] = 0;
    }
}

int foo() {
    unsigned j;
    struct hash_node *n
    ctxsensfunc(n->w_key, n->xo);
    j = n->lo;
    ctxsensfunc(n->y_key, j);
    return 0;
}

@Machiry Machiry linked an issue Sep 15, 2020 that may be closed by this pull request
Comment thread clang/include/clang/CConv/ProgramVar.h Outdated
Comment thread clang/include/clang/CConv/ProgramVar.h Outdated

static FunctionParamScope *getFunctionParamScope(std::string FnName,
bool IsSt);
std::string getFName() const {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this instead return a const std::string & or llvm::StringRef to avoid copying the string?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Done.

Comment thread clang/lib/CConv/ProgramVar.cpp Outdated
@Machiry

Machiry commented Sep 20, 2020

Copy link
Copy Markdown
Collaborator Author

@jackastner Do these changes look good to you?

@john-h-kastner john-h-kastner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@Machiry Machiry merged commit 1036b6e into BigRefactor Sep 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Required Changes to Arr Bounds Inference

2 participants